/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package BoardGameToTreeIntegration.Rules.impl;

import BoardGame.Board;
import BoardGame.BoardGameFactory;

import BoardGameToTreeIntegration.BoardGameToTreeIntegrationFactory;
import BoardGameToTreeIntegration.BoardToFile;

import BoardGameToTreeIntegration.BoardToNode;
import BoardGameToTreeIntegration.Rules.BoardRule;
import BoardGameToTreeIntegration.Rules.RulesPackage;

import MocaTree.File;
import MocaTree.MocaTreeFactory;

import MocaTree.Node;
import TGGLanguage.csp.*;

import TGGRuntime.Edge;
import TGGRuntime.IsAppropriateRuleResult;
import TGGRuntime.Match;
import TGGRuntime.PerformRuleResult;
import TGGRuntime.TGGRuntimeFactory;

import TGGRuntime.impl.AbstractRuleImpl;

import csp.constraints.*;

import de.upb.tools.sdm.*;

import java.lang.reflect.InvocationTargetException;

import java.util.*;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EOperation;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Board Rule</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * </p>
 *
 * @generated
 */
public class BoardRuleImpl extends AbstractRuleImpl implements BoardRule {
	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected BoardRuleImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return RulesPackage.Literals.BOARD_RULE;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public PerformRuleResult perform_FWD_Board_0(Board board) {
		boolean fujaba__Success = false;
		PerformRuleResult ruleResult = null;
		BoardToFile b2f = null;
		BoardToNode b2n = null;
		File file = null;
		Node root = null;
		Edge b2f__target__file = null;
		Edge b2n__target__root = null;
		Edge root__file__file = null;
		Edge b2f__source__board = null;
		Edge b2n__source__board = null;

		// story pattern prepare return value
		try {
			fujaba__Success = false;

			// create object ruleResult
			ruleResult = TGGRuntimeFactory.eINSTANCE.createPerformRuleResult();
			// assign attribute ruleResult
			ruleResult.setSuccess(false);
			fujaba__Success = true;
		} catch (JavaSDMException fujaba__InternalException) {
			fujaba__Success = false;
		}

		// story pattern find context
		try {
			fujaba__Success = false;

			// check object board is really bound
			JavaSDM.ensure(board != null);
			// Create CSP
			CSP csp = CspFactory.eINSTANCE.createCSP();

			// Create literals
			Variable<String> literal0 = CspFactory.eINSTANCE.createVariable(
					"literal0", true, csp);
			literal0.setValue("BOARD");
			Variable<Integer> literal1 = CspFactory.eINSTANCE.createVariable(
					"literal1", true, csp);
			literal1.setValue(0);

			// Create implicit parameters

			// Create explicit parameters

			// Create unbound variables
			Variable<String> var_root_name = CspFactory.eINSTANCE
					.createVariable("root.name", csp);
			Variable<Integer> var_root_index = CspFactory.eINSTANCE
					.createVariable("root.index", csp);

			// Create constraints
			Eq<String> eq = new Eq<String>();
			Eq<Integer> eq_0 = new Eq<Integer>();

			csp.getConstraints().add(eq);
			csp.getConstraints().add(eq_0);

			// Solve CSP
			eq.solve(var_root_name, literal0);
			eq_0.solve(var_root_index, literal1);

			fujaba__Success = csp.check();
			if (fujaba__Success) {
				// story pattern perform transformation
				try {
					fujaba__Success = false;

					// check object board is really bound
					JavaSDM.ensure(board != null);
					// create object b2f
					b2f = BoardGameToTreeIntegrationFactory.eINSTANCE
							.createBoardToFile();
					// create object b2n
					b2n = BoardGameToTreeIntegrationFactory.eINSTANCE
							.createBoardToNode();
					// create object file
					file = MocaTreeFactory.eINSTANCE.createFile();
					// create object root
					root = MocaTreeFactory.eINSTANCE.createNode();
					// assign attribute root
					root.setName(var_root_name.getValue());
					// assign attribute root
					root.setIndex(var_root_index.getValue());
					// create link
					b2f.setSource(board);

					// create link
					b2n.setSource(board);

					// create link
					root.setFile(file);

					// create link
					b2f.setTarget(file);

					// create link
					b2n.setTarget(root);

					fujaba__Success = true;
				} catch (JavaSDMException fujaba__InternalException) {
					fujaba__Success = false;
				}

				// story pattern collect translated elements
				try {
					fujaba__Success = false;

					// check object b2f is really bound
					JavaSDM.ensure(b2f != null);
					// check object b2n is really bound
					JavaSDM.ensure(b2n != null);
					// check object board is really bound
					JavaSDM.ensure(board != null);
					// check object file is really bound
					JavaSDM.ensure(file != null);
					// check object root is really bound
					JavaSDM.ensure(root != null);
					// check object ruleResult is really bound
					JavaSDM.ensure(ruleResult != null);
					// assign attribute ruleResult
					ruleResult.setSuccess(true);
					// create link
					org.moflon.util.eMoflonEMFUtil.addOppositeReference(
							ruleResult, file, "createdElements");
					// create link
					org.moflon.util.eMoflonEMFUtil.addOppositeReference(
							ruleResult, b2f, "createdLinkElements");
					// create link
					org.moflon.util.eMoflonEMFUtil.addOppositeReference(
							ruleResult, board, "translatedElements");
					// create link
					org.moflon.util.eMoflonEMFUtil.addOppositeReference(
							ruleResult, b2n, "createdLinkElements");
					// create link
					org.moflon.util.eMoflonEMFUtil.addOppositeReference(
							ruleResult, root, "createdElements");
					fujaba__Success = true;
				} catch (JavaSDMException fujaba__InternalException) {
					fujaba__Success = false;
				}

				// story pattern bookkeeping for edges
				try {
					fujaba__Success = false;

					// check object b2f is really bound
					JavaSDM.ensure(b2f != null);
					// check object b2n is really bound
					JavaSDM.ensure(b2n != null);
					// check object board is really bound
					JavaSDM.ensure(board != null);
					// check object file is really bound
					JavaSDM.ensure(file != null);
					// check object root is really bound
					JavaSDM.ensure(root != null);
					// check object ruleResult is really bound
					JavaSDM.ensure(ruleResult != null);
					// check isomorphic binding between objects b2n and b2f
					JavaSDM.ensure(!b2n.equals(b2f));

					// check isomorphic binding between objects board and b2f
					JavaSDM.ensure(!board.equals(b2f));

					// check isomorphic binding between objects file and b2f
					JavaSDM.ensure(!file.equals(b2f));

					// check isomorphic binding between objects root and b2f
					JavaSDM.ensure(!root.equals(b2f));

					// check isomorphic binding between objects board and b2n
					JavaSDM.ensure(!board.equals(b2n));

					// check isomorphic binding between objects file and b2n
					JavaSDM.ensure(!file.equals(b2n));

					// check isomorphic binding between objects root and b2n
					JavaSDM.ensure(!root.equals(b2n));

					// check isomorphic binding between objects file and board
					JavaSDM.ensure(!file.equals(board));

					// check isomorphic binding between objects root and board
					JavaSDM.ensure(!root.equals(board));

					// check isomorphic binding between objects root and file
					JavaSDM.ensure(!root.equals(file));

					// create object b2f__target__file
					b2f__target__file = TGGRuntimeFactory.eINSTANCE
							.createEdge();
					// create object b2n__target__root
					b2n__target__root = TGGRuntimeFactory.eINSTANCE
							.createEdge();
					// create object root__file__file
					root__file__file = TGGRuntimeFactory.eINSTANCE.createEdge();
					// create object b2f__source__board
					b2f__source__board = TGGRuntimeFactory.eINSTANCE
							.createEdge();
					// create object b2n__source__board
					b2n__source__board = TGGRuntimeFactory.eINSTANCE
							.createEdge();
					// assign attribute b2f__source__board
					b2f__source__board.setName("b2f__source__board");
					// assign attribute b2f__target__file
					b2f__target__file.setName("b2f__target__file");
					// assign attribute root__file__file
					root__file__file.setName("root__file__file");
					// assign attribute b2n__source__board
					b2n__source__board.setName("b2n__source__board");
					// assign attribute b2n__target__root
					b2n__target__root.setName("b2n__target__root");
					// create link
					org.moflon.util.eMoflonEMFUtil.addOppositeReference(
							ruleResult, b2f__target__file, "createdEdges");
					// create link
					org.moflon.util.eMoflonEMFUtil.addOppositeReference(
							ruleResult, b2n__target__root, "createdEdges");
					// create link
					org.moflon.util.eMoflonEMFUtil.addOppositeReference(
							ruleResult, root__file__file, "createdEdges");
					// create link
					org.moflon.util.eMoflonEMFUtil.addOppositeReference(
							ruleResult, b2f__source__board, "createdEdges");
					// create link
					org.moflon.util.eMoflonEMFUtil.addOppositeReference(
							ruleResult, b2n__source__board, "createdEdges");
					// create link
					b2f__source__board.setTrg(board);

					// create link
					b2n__source__board.setTrg(board);

					// create link
					b2f__target__file.setTrg(file);

					// create link
					root__file__file.setTrg(file);

					// create link
					b2f__target__file.setSrc(b2f);

					// create link
					b2f__source__board.setSrc(b2f);

					// create link
					root__file__file.setSrc(root);

					// create link
					b2n__target__root.setTrg(root);

					// create link
					b2n__source__board.setSrc(b2n);

					// create link
					b2n__target__root.setSrc(b2n);

					fujaba__Success = true;
				} catch (JavaSDMException fujaba__InternalException) {
					fujaba__Success = false;
				}

				return ruleResult;

			}
			fujaba__Success = true;
		} catch (JavaSDMException fujaba__InternalException) {
			fujaba__Success = false;
		}

		return ruleResult;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public IsAppropriateRuleResult isAppropriate_FWD_Board_0(Board board) {
		boolean fujaba__Success = false;
		Object _TmpObject = null;
		EClass eClass = null;
		Iterator fujaba__IterEClassToPerformOperation = null;
		EOperation performOperation = null;
		IsAppropriateRuleResult ruleResult = null;
		Match match = null;
		Iterator fujaba__IterRuleResultToMatch = null;

		// story pattern prepare return value
		try {
			fujaba__Success = false;

			_TmpObject = (this.eClass());

			// ensure correct type and really bound of object eClass
			JavaSDM.ensure(_TmpObject instanceof EClass);
			eClass = (EClass) _TmpObject;

			// iterate to-many link eOperations from eClass to performOperation
			fujaba__Success = false;

			fujaba__IterEClassToPerformOperation = eClass.getEOperations()
					.iterator();

			while (!(fujaba__Success)
					&& fujaba__IterEClassToPerformOperation.hasNext()) {
				try {
					performOperation = (EOperation) fujaba__IterEClassToPerformOperation
							.next();

					// check object performOperation is really bound
					JavaSDM.ensure(performOperation != null);
					// attribute condition
					JavaSDM.ensure(JavaSDM.stringCompare(
							performOperation.getName(), "perform_FWD_Board_0") == 0);

					fujaba__Success = true;
				} catch (JavaSDMException fujaba__InternalException) {
					fujaba__Success = false;
				}
			}
			JavaSDM.ensure(fujaba__Success);
			// create object ruleResult
			ruleResult = TGGRuntimeFactory.eINSTANCE
					.createIsAppropriateRuleResult();
			// assign attribute ruleResult
			ruleResult.setSuccess(false);
			// create link
			ruleResult.setPerformOperation(performOperation);

			fujaba__Success = true;
		} catch (JavaSDMException fujaba__InternalException) {
			fujaba__Success = false;
		}

		// story pattern test core match
		try {
			fujaba__Success = false;

			// check object board is really bound
			JavaSDM.ensure(board != null);
			// check object ruleResult is really bound
			JavaSDM.ensure(ruleResult != null);
			// create object match
			match = TGGRuntimeFactory.eINSTANCE.createMatch();
			// create link
			ruleResult.getMatches().add(match);

			// story pattern collect elements to be translated
			try {
				fujaba__Success = false;

				// check object board is really bound
				JavaSDM.ensure(board != null);
				// check object match is really bound
				JavaSDM.ensure(match != null);
				// create link
				org.moflon.util.eMoflonEMFUtil.addOppositeReference(match,
						board, "toBeTranslatedElements");
				fujaba__Success = true;
			} catch (JavaSDMException fujaba__InternalException) {
				fujaba__Success = false;
			}

			// story pattern collect context nodes
			try {
				fujaba__Success = false;

				// check object match is really bound
				JavaSDM.ensure(match != null);
				fujaba__Success = true;
			} catch (JavaSDMException fujaba__InternalException) {
				fujaba__Success = false;
			}

			fujaba__Success = true;
		} catch (JavaSDMException fujaba__InternalException) {
			fujaba__Success = false;
		}

		// story pattern set success
		try {
			fujaba__Success = false;

			// check object ruleResult is really bound
			JavaSDM.ensure(ruleResult != null);
			// iterate to-many link matches from ruleResult to match
			fujaba__Success = false;

			fujaba__IterRuleResultToMatch = ruleResult.getMatches().iterator();

			while (!(fujaba__Success)
					&& fujaba__IterRuleResultToMatch.hasNext()) {
				try {
					match = (Match) fujaba__IterRuleResultToMatch.next();

					// check object match is really bound
					JavaSDM.ensure(match != null);

					fujaba__Success = true;
				} catch (JavaSDMException fujaba__InternalException) {
					fujaba__Success = false;
				}
			}
			JavaSDM.ensure(fujaba__Success);
			// assign attribute ruleResult
			ruleResult.setSuccess(true);
			fujaba__Success = true;
		} catch (JavaSDMException fujaba__InternalException) {
			fujaba__Success = false;
		}

		return ruleResult;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public PerformRuleResult perform_BWD_File_0(File file) {
		boolean fujaba__Success = false;
		PerformRuleResult ruleResult = null;
		Board board = null;
		BoardToFile b2f = null;
		BoardToNode b2n = null;
		Edge b2f__source__board = null;
		Edge b2f__target__file = null;
		Edge b2n__target__root = null;
		Edge root__file__file = null;
		Edge b2n__source__board = null;
		Node root = null;

		// story pattern prepare return value
		try {
			fujaba__Success = false;

			// create object ruleResult
			ruleResult = TGGRuntimeFactory.eINSTANCE.createPerformRuleResult();
			// assign attribute ruleResult
			ruleResult.setSuccess(false);
			fujaba__Success = true;
		} catch (JavaSDMException fujaba__InternalException) {
			fujaba__Success = false;
		}

		// story pattern find context
		try {
			fujaba__Success = false;

			// check object file is really bound
			JavaSDM.ensure(file != null);
			// bind object
			root = file.getRootNode();

			// check object root is really bound
			JavaSDM.ensure(root != null);

			// Create CSP
			CSP csp = CspFactory.eINSTANCE.createCSP();

			// Create literals
			Variable<String> literal0 = CspFactory.eINSTANCE.createVariable(
					"literal0", true, csp);
			literal0.setValue("BOARD");
			Variable<Integer> literal1 = CspFactory.eINSTANCE.createVariable(
					"literal1", true, csp);
			literal1.setValue(0);

			// Create implicit parameters
			Variable<String> var_root_name = CspFactory.eINSTANCE
					.createVariable("root.name", true, csp);
			var_root_name.setValue(root.getName());
			Variable<Integer> var_root_index = CspFactory.eINSTANCE
					.createVariable("root.index", true, csp);
			var_root_index.setValue(root.getIndex());

			// Create explicit parameters

			// Create unbound variables

			// Create constraints
			Eq<String> eq = new Eq<String>();
			Eq<Integer> eq_0 = new Eq<Integer>();

			csp.getConstraints().add(eq);
			csp.getConstraints().add(eq_0);

			// Solve CSP
			eq.solve(var_root_name, literal0);
			eq_0.solve(var_root_index, literal1);

			fujaba__Success = csp.check();
			if (fujaba__Success) {
				// story pattern perform transformation
				try {
					fujaba__Success = false;

					// check object file is really bound
					JavaSDM.ensure(file != null);
					// check object root is really bound
					JavaSDM.ensure(root != null);
					// check link rootNode from root to file
					JavaSDM.ensure(file.equals(root.getFile()));

					// create object board
					board = BoardGameFactory.eINSTANCE.createBoard();
					// create object b2f
					b2f = BoardGameToTreeIntegrationFactory.eINSTANCE
							.createBoardToFile();
					// create object b2n
					b2n = BoardGameToTreeIntegrationFactory.eINSTANCE
							.createBoardToNode();
					// create link
					b2f.setSource(board);

					// create link
					b2n.setSource(board);

					// create link
					b2f.setTarget(file);

					// create link
					b2n.setTarget(root);

					fujaba__Success = true;
				} catch (JavaSDMException fujaba__InternalException) {
					fujaba__Success = false;
				}

				// story pattern collect translated elements
				try {
					fujaba__Success = false;

					// check object b2f is really bound
					JavaSDM.ensure(b2f != null);
					// check object b2n is really bound
					JavaSDM.ensure(b2n != null);
					// check object board is really bound
					JavaSDM.ensure(board != null);
					// check object file is really bound
					JavaSDM.ensure(file != null);
					// check object root is really bound
					JavaSDM.ensure(root != null);
					// check object ruleResult is really bound
					JavaSDM.ensure(ruleResult != null);
					// assign attribute ruleResult
					ruleResult.setSuccess(true);
					// create link
					org.moflon.util.eMoflonEMFUtil.addOppositeReference(
							ruleResult, file, "translatedElements");
					// create link
					org.moflon.util.eMoflonEMFUtil.addOppositeReference(
							ruleResult, b2n, "createdLinkElements");
					// create link
					org.moflon.util.eMoflonEMFUtil.addOppositeReference(
							ruleResult, root, "translatedElements");
					// create link
					org.moflon.util.eMoflonEMFUtil.addOppositeReference(
							ruleResult, board, "createdElements");
					// create link
					org.moflon.util.eMoflonEMFUtil.addOppositeReference(
							ruleResult, b2f, "createdLinkElements");
					fujaba__Success = true;
				} catch (JavaSDMException fujaba__InternalException) {
					fujaba__Success = false;
				}

				// story pattern bookkeeping for edges
				try {
					fujaba__Success = false;

					// check object b2f is really bound
					JavaSDM.ensure(b2f != null);
					// check object b2n is really bound
					JavaSDM.ensure(b2n != null);
					// check object board is really bound
					JavaSDM.ensure(board != null);
					// check object file is really bound
					JavaSDM.ensure(file != null);
					// check object root is really bound
					JavaSDM.ensure(root != null);
					// check object ruleResult is really bound
					JavaSDM.ensure(ruleResult != null);
					// check isomorphic binding between objects b2n and b2f
					JavaSDM.ensure(!b2n.equals(b2f));

					// check isomorphic binding between objects board and b2f
					JavaSDM.ensure(!board.equals(b2f));

					// check isomorphic binding between objects file and b2f
					JavaSDM.ensure(!file.equals(b2f));

					// check isomorphic binding between objects root and b2f
					JavaSDM.ensure(!root.equals(b2f));

					// check isomorphic binding between objects board and b2n
					JavaSDM.ensure(!board.equals(b2n));

					// check isomorphic binding between objects file and b2n
					JavaSDM.ensure(!file.equals(b2n));

					// check isomorphic binding between objects root and b2n
					JavaSDM.ensure(!root.equals(b2n));

					// check isomorphic binding between objects file and board
					JavaSDM.ensure(!file.equals(board));

					// check isomorphic binding between objects root and board
					JavaSDM.ensure(!root.equals(board));

					// check isomorphic binding between objects root and file
					JavaSDM.ensure(!root.equals(file));

					// create object b2f__source__board
					b2f__source__board = TGGRuntimeFactory.eINSTANCE
							.createEdge();
					// create object b2f__target__file
					b2f__target__file = TGGRuntimeFactory.eINSTANCE
							.createEdge();
					// create object b2n__target__root
					b2n__target__root = TGGRuntimeFactory.eINSTANCE
							.createEdge();
					// create object root__file__file
					root__file__file = TGGRuntimeFactory.eINSTANCE.createEdge();
					// create object b2n__source__board
					b2n__source__board = TGGRuntimeFactory.eINSTANCE
							.createEdge();
					// assign attribute b2f__source__board
					b2f__source__board.setName("b2f__source__board");
					// assign attribute b2f__target__file
					b2f__target__file.setName("b2f__target__file");
					// assign attribute root__file__file
					root__file__file.setName("file");
					// assign attribute b2n__source__board
					b2n__source__board.setName("b2n__source__board");
					// assign attribute b2n__target__root
					b2n__target__root.setName("b2n__target__root");
					// create link
					org.moflon.util.eMoflonEMFUtil.addOppositeReference(
							ruleResult, b2f__source__board, "createdEdges");
					// create link
					org.moflon.util.eMoflonEMFUtil.addOppositeReference(
							ruleResult, b2f__target__file, "createdEdges");
					// create link
					org.moflon.util.eMoflonEMFUtil.addOppositeReference(
							ruleResult, b2n__target__root, "createdEdges");
					// create link
					org.moflon.util.eMoflonEMFUtil.addOppositeReference(
							ruleResult, root__file__file, "translatedEdges");
					// create link
					org.moflon.util.eMoflonEMFUtil.addOppositeReference(
							ruleResult, b2n__source__board, "createdEdges");
					// create link
					b2n__source__board.setTrg(board);

					// create link
					b2f__source__board.setTrg(board);

					// create link
					b2f__target__file.setTrg(file);

					// create link
					root__file__file.setTrg(file);

					// create link
					b2f__source__board.setSrc(b2f);

					// create link
					b2f__target__file.setSrc(b2f);

					// create link
					root__file__file.setSrc(root);

					// create link
					b2n__target__root.setTrg(root);

					// create link
					b2n__source__board.setSrc(b2n);

					// create link
					b2n__target__root.setSrc(b2n);

					fujaba__Success = true;
				} catch (JavaSDMException fujaba__InternalException) {
					fujaba__Success = false;
				}

				return ruleResult;

			}

			fujaba__Success = true;
		} catch (JavaSDMException fujaba__InternalException) {
			fujaba__Success = false;
		}

		return ruleResult;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public IsAppropriateRuleResult isAppropriate_BWD_File_0(File file) {
		boolean fujaba__Success = false;
		Object _TmpObject = null;
		EClass eClass = null;
		Iterator fujaba__IterEClassToPerformOperation = null;
		EOperation performOperation = null;
		IsAppropriateRuleResult ruleResult = null;
		Match match = null;
		Edge root__file__file = null;
		Node root = null;
		Iterator fujaba__IterRuleResultToMatch = null;

		// story pattern prepare return value
		try {
			fujaba__Success = false;

			_TmpObject = (this.eClass());

			// ensure correct type and really bound of object eClass
			JavaSDM.ensure(_TmpObject instanceof EClass);
			eClass = (EClass) _TmpObject;

			// iterate to-many link eOperations from eClass to performOperation
			fujaba__Success = false;

			fujaba__IterEClassToPerformOperation = eClass.getEOperations()
					.iterator();

			while (!(fujaba__Success)
					&& fujaba__IterEClassToPerformOperation.hasNext()) {
				try {
					performOperation = (EOperation) fujaba__IterEClassToPerformOperation
							.next();

					// check object performOperation is really bound
					JavaSDM.ensure(performOperation != null);
					// attribute condition
					JavaSDM.ensure(JavaSDM.stringCompare(
							performOperation.getName(), "perform_BWD_File_0") == 0);

					fujaba__Success = true;
				} catch (JavaSDMException fujaba__InternalException) {
					fujaba__Success = false;
				}
			}
			JavaSDM.ensure(fujaba__Success);
			// create object ruleResult
			ruleResult = TGGRuntimeFactory.eINSTANCE
					.createIsAppropriateRuleResult();
			// assign attribute ruleResult
			ruleResult.setSuccess(false);
			// create link
			ruleResult.setPerformOperation(performOperation);

			fujaba__Success = true;
		} catch (JavaSDMException fujaba__InternalException) {
			fujaba__Success = false;
		}

		// story pattern test core match
		try {
			fujaba__Success = false;

			// check object file is really bound
			JavaSDM.ensure(file != null);
			// check object ruleResult is really bound
			JavaSDM.ensure(ruleResult != null);
			// bind object
			root = file.getRootNode();

			// check object root is really bound
			JavaSDM.ensure(root != null);

			// create object match
			match = TGGRuntimeFactory.eINSTANCE.createMatch();
			// create link
			ruleResult.getMatches().add(match);

			// story pattern collect elements to be translated
			try {
				fujaba__Success = false;

				// check object file is really bound
				JavaSDM.ensure(file != null);
				// check object match is really bound
				JavaSDM.ensure(match != null);
				// check object root is really bound
				JavaSDM.ensure(root != null);
				// create object root__file__file
				root__file__file = TGGRuntimeFactory.eINSTANCE.createEdge();
				// assign attribute root__file__file
				root__file__file.setName("file");
				// create link
				org.moflon.util.eMoflonEMFUtil.addOppositeReference(match,
						root, "toBeTranslatedElements");
				// create link
				org.moflon.util.eMoflonEMFUtil.addOppositeReference(match,
						file, "toBeTranslatedElements");
				// create link
				org.moflon.util.eMoflonEMFUtil.addOppositeReference(match,
						root__file__file, "toBeTranslatedEdges");
				// create link
				root__file__file.setTrg(file);

				// create link
				root__file__file.setSrc(root);

				fujaba__Success = true;
			} catch (JavaSDMException fujaba__InternalException) {
				fujaba__Success = false;
			}

			// story pattern collect context nodes
			try {
				fujaba__Success = false;

				// check object match is really bound
				JavaSDM.ensure(match != null);
				fujaba__Success = true;
			} catch (JavaSDMException fujaba__InternalException) {
				fujaba__Success = false;
			}

			fujaba__Success = true;
		} catch (JavaSDMException fujaba__InternalException) {
			fujaba__Success = false;
		}

		// story pattern set success
		try {
			fujaba__Success = false;

			// check object ruleResult is really bound
			JavaSDM.ensure(ruleResult != null);
			// iterate to-many link matches from ruleResult to match
			fujaba__Success = false;

			fujaba__IterRuleResultToMatch = ruleResult.getMatches().iterator();

			while (!(fujaba__Success)
					&& fujaba__IterRuleResultToMatch.hasNext()) {
				try {
					match = (Match) fujaba__IterRuleResultToMatch.next();

					// check object match is really bound
					JavaSDM.ensure(match != null);

					fujaba__Success = true;
				} catch (JavaSDMException fujaba__InternalException) {
					fujaba__Success = false;
				}
			}
			JavaSDM.ensure(fujaba__Success);
			// assign attribute ruleResult
			ruleResult.setSuccess(true);
			fujaba__Success = true;
		} catch (JavaSDMException fujaba__InternalException) {
			fujaba__Success = false;
		}

		return ruleResult;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public PerformRuleResult perform_BWD_Node_0(Node root) {
		boolean fujaba__Success = false;
		PerformRuleResult ruleResult = null;
		Board board = null;
		BoardToNode b2n = null;
		BoardToFile b2f = null;
		Edge b2f__source__board = null;
		Edge root__file__file = null;
		Edge b2n__source__board = null;
		Edge b2n__target__root = null;
		Edge b2f__target__file = null;
		File file = null;

		// story pattern prepare return value
		try {
			fujaba__Success = false;

			// create object ruleResult
			ruleResult = TGGRuntimeFactory.eINSTANCE.createPerformRuleResult();
			// assign attribute ruleResult
			ruleResult.setSuccess(false);
			fujaba__Success = true;
		} catch (JavaSDMException fujaba__InternalException) {
			fujaba__Success = false;
		}

		// story pattern find context
		try {
			fujaba__Success = false;

			// check object root is really bound
			JavaSDM.ensure(root != null);
			// bind object
			file = root.getFile();

			// check object file is really bound
			JavaSDM.ensure(file != null);

			// Create CSP
			CSP csp = CspFactory.eINSTANCE.createCSP();

			// Create literals
			Variable<String> literal0 = CspFactory.eINSTANCE.createVariable(
					"literal0", true, csp);
			literal0.setValue("BOARD");
			Variable<Integer> literal1 = CspFactory.eINSTANCE.createVariable(
					"literal1", true, csp);
			literal1.setValue(0);

			// Create implicit parameters
			Variable<String> var_root_name = CspFactory.eINSTANCE
					.createVariable("root.name", true, csp);
			var_root_name.setValue(root.getName());
			Variable<Integer> var_root_index = CspFactory.eINSTANCE
					.createVariable("root.index", true, csp);
			var_root_index.setValue(root.getIndex());

			// Create explicit parameters

			// Create unbound variables

			// Create constraints
			Eq<String> eq = new Eq<String>();
			Eq<Integer> eq_0 = new Eq<Integer>();

			csp.getConstraints().add(eq);
			csp.getConstraints().add(eq_0);

			// Solve CSP
			eq.solve(var_root_name, literal0);
			eq_0.solve(var_root_index, literal1);

			fujaba__Success = csp.check();
			if (fujaba__Success) {
				// story pattern perform transformation
				try {
					fujaba__Success = false;

					// check object file is really bound
					JavaSDM.ensure(file != null);
					// check object root is really bound
					JavaSDM.ensure(root != null);
					// check link rootNode from root to file
					JavaSDM.ensure(file.equals(root.getFile()));

					// create object board
					board = BoardGameFactory.eINSTANCE.createBoard();
					// create object b2n
					b2n = BoardGameToTreeIntegrationFactory.eINSTANCE
							.createBoardToNode();
					// create object b2f
					b2f = BoardGameToTreeIntegrationFactory.eINSTANCE
							.createBoardToFile();
					// create link
					b2n.setSource(board);

					// create link
					b2f.setSource(board);

					// create link
					b2f.setTarget(file);

					// create link
					b2n.setTarget(root);

					fujaba__Success = true;
				} catch (JavaSDMException fujaba__InternalException) {
					fujaba__Success = false;
				}

				// story pattern collect translated elements
				try {
					fujaba__Success = false;

					// check object b2f is really bound
					JavaSDM.ensure(b2f != null);
					// check object b2n is really bound
					JavaSDM.ensure(b2n != null);
					// check object board is really bound
					JavaSDM.ensure(board != null);
					// check object file is really bound
					JavaSDM.ensure(file != null);
					// check object root is really bound
					JavaSDM.ensure(root != null);
					// check object ruleResult is really bound
					JavaSDM.ensure(ruleResult != null);
					// assign attribute ruleResult
					ruleResult.setSuccess(true);
					// create link
					org.moflon.util.eMoflonEMFUtil.addOppositeReference(
							ruleResult, root, "translatedElements");
					// create link
					org.moflon.util.eMoflonEMFUtil.addOppositeReference(
							ruleResult, b2f, "createdLinkElements");
					// create link
					org.moflon.util.eMoflonEMFUtil.addOppositeReference(
							ruleResult, b2n, "createdLinkElements");
					// create link
					org.moflon.util.eMoflonEMFUtil.addOppositeReference(
							ruleResult, file, "translatedElements");
					// create link
					org.moflon.util.eMoflonEMFUtil.addOppositeReference(
							ruleResult, board, "createdElements");
					fujaba__Success = true;
				} catch (JavaSDMException fujaba__InternalException) {
					fujaba__Success = false;
				}

				// story pattern bookkeeping for edges
				try {
					fujaba__Success = false;

					// check object b2f is really bound
					JavaSDM.ensure(b2f != null);
					// check object b2n is really bound
					JavaSDM.ensure(b2n != null);
					// check object board is really bound
					JavaSDM.ensure(board != null);
					// check object file is really bound
					JavaSDM.ensure(file != null);
					// check object root is really bound
					JavaSDM.ensure(root != null);
					// check object ruleResult is really bound
					JavaSDM.ensure(ruleResult != null);
					// check isomorphic binding between objects b2n and b2f
					JavaSDM.ensure(!b2n.equals(b2f));

					// check isomorphic binding between objects board and b2f
					JavaSDM.ensure(!board.equals(b2f));

					// check isomorphic binding between objects file and b2f
					JavaSDM.ensure(!file.equals(b2f));

					// check isomorphic binding between objects root and b2f
					JavaSDM.ensure(!root.equals(b2f));

					// check isomorphic binding between objects board and b2n
					JavaSDM.ensure(!board.equals(b2n));

					// check isomorphic binding between objects file and b2n
					JavaSDM.ensure(!file.equals(b2n));

					// check isomorphic binding between objects root and b2n
					JavaSDM.ensure(!root.equals(b2n));

					// check isomorphic binding between objects file and board
					JavaSDM.ensure(!file.equals(board));

					// check isomorphic binding between objects root and board
					JavaSDM.ensure(!root.equals(board));

					// check isomorphic binding between objects root and file
					JavaSDM.ensure(!root.equals(file));

					// create object b2f__source__board
					b2f__source__board = TGGRuntimeFactory.eINSTANCE
							.createEdge();
					// create object root__file__file
					root__file__file = TGGRuntimeFactory.eINSTANCE.createEdge();
					// create object b2n__source__board
					b2n__source__board = TGGRuntimeFactory.eINSTANCE
							.createEdge();
					// create object b2n__target__root
					b2n__target__root = TGGRuntimeFactory.eINSTANCE
							.createEdge();
					// create object b2f__target__file
					b2f__target__file = TGGRuntimeFactory.eINSTANCE
							.createEdge();
					// assign attribute b2f__source__board
					b2f__source__board.setName("b2f__source__board");
					// assign attribute b2f__target__file
					b2f__target__file.setName("b2f__target__file");
					// assign attribute root__file__file
					root__file__file.setName("file");
					// assign attribute b2n__source__board
					b2n__source__board.setName("b2n__source__board");
					// assign attribute b2n__target__root
					b2n__target__root.setName("b2n__target__root");
					// create link
					org.moflon.util.eMoflonEMFUtil.addOppositeReference(
							ruleResult, b2f__source__board, "createdEdges");
					// create link
					org.moflon.util.eMoflonEMFUtil.addOppositeReference(
							ruleResult, root__file__file, "translatedEdges");
					// create link
					org.moflon.util.eMoflonEMFUtil.addOppositeReference(
							ruleResult, b2n__source__board, "createdEdges");
					// create link
					org.moflon.util.eMoflonEMFUtil.addOppositeReference(
							ruleResult, b2n__target__root, "createdEdges");
					// create link
					org.moflon.util.eMoflonEMFUtil.addOppositeReference(
							ruleResult, b2f__target__file, "createdEdges");
					// create link
					b2f__source__board.setTrg(board);

					// create link
					b2n__source__board.setTrg(board);

					// create link
					root__file__file.setTrg(file);

					// create link
					b2f__target__file.setTrg(file);

					// create link
					b2f__source__board.setSrc(b2f);

					// create link
					b2f__target__file.setSrc(b2f);

					// create link
					b2n__target__root.setTrg(root);

					// create link
					root__file__file.setSrc(root);

					// create link
					b2n__target__root.setSrc(b2n);

					// create link
					b2n__source__board.setSrc(b2n);

					fujaba__Success = true;
				} catch (JavaSDMException fujaba__InternalException) {
					fujaba__Success = false;
				}

				return ruleResult;

			}

			fujaba__Success = true;
		} catch (JavaSDMException fujaba__InternalException) {
			fujaba__Success = false;
		}

		return ruleResult;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public IsAppropriateRuleResult isAppropriate_BWD_Node_0(Node root) {
		boolean fujaba__Success = false;
		Object _TmpObject = null;
		EClass eClass = null;
		Iterator fujaba__IterEClassToPerformOperation = null;
		EOperation performOperation = null;
		IsAppropriateRuleResult ruleResult = null;
		Match match = null;
		Edge root__file__file = null;
		File file = null;
		Iterator fujaba__IterRuleResultToMatch = null;

		// story pattern prepare return value
		try {
			fujaba__Success = false;

			_TmpObject = (this.eClass());

			// ensure correct type and really bound of object eClass
			JavaSDM.ensure(_TmpObject instanceof EClass);
			eClass = (EClass) _TmpObject;

			// iterate to-many link eOperations from eClass to performOperation
			fujaba__Success = false;

			fujaba__IterEClassToPerformOperation = eClass.getEOperations()
					.iterator();

			while (!(fujaba__Success)
					&& fujaba__IterEClassToPerformOperation.hasNext()) {
				try {
					performOperation = (EOperation) fujaba__IterEClassToPerformOperation
							.next();

					// check object performOperation is really bound
					JavaSDM.ensure(performOperation != null);
					// attribute condition
					JavaSDM.ensure(JavaSDM.stringCompare(
							performOperation.getName(), "perform_BWD_Node_0") == 0);

					fujaba__Success = true;
				} catch (JavaSDMException fujaba__InternalException) {
					fujaba__Success = false;
				}
			}
			JavaSDM.ensure(fujaba__Success);
			// create object ruleResult
			ruleResult = TGGRuntimeFactory.eINSTANCE
					.createIsAppropriateRuleResult();
			// assign attribute ruleResult
			ruleResult.setSuccess(false);
			// create link
			ruleResult.setPerformOperation(performOperation);

			fujaba__Success = true;
		} catch (JavaSDMException fujaba__InternalException) {
			fujaba__Success = false;
		}

		// story pattern test core match
		try {
			fujaba__Success = false;

			// check object root is really bound
			JavaSDM.ensure(root != null);
			// check object ruleResult is really bound
			JavaSDM.ensure(ruleResult != null);
			// bind object
			file = root.getFile();

			// check object file is really bound
			JavaSDM.ensure(file != null);

			// create object match
			match = TGGRuntimeFactory.eINSTANCE.createMatch();
			// create link
			ruleResult.getMatches().add(match);

			// story pattern collect elements to be translated
			try {
				fujaba__Success = false;

				// check object file is really bound
				JavaSDM.ensure(file != null);
				// check object match is really bound
				JavaSDM.ensure(match != null);
				// check object root is really bound
				JavaSDM.ensure(root != null);
				// create object root__file__file
				root__file__file = TGGRuntimeFactory.eINSTANCE.createEdge();
				// assign attribute root__file__file
				root__file__file.setName("file");
				// create link
				org.moflon.util.eMoflonEMFUtil.addOppositeReference(match,
						file, "toBeTranslatedElements");
				// create link
				org.moflon.util.eMoflonEMFUtil.addOppositeReference(match,
						root, "toBeTranslatedElements");
				// create link
				org.moflon.util.eMoflonEMFUtil.addOppositeReference(match,
						root__file__file, "toBeTranslatedEdges");
				// create link
				root__file__file.setTrg(file);

				// create link
				root__file__file.setSrc(root);

				fujaba__Success = true;
			} catch (JavaSDMException fujaba__InternalException) {
				fujaba__Success = false;
			}

			// story pattern collect context nodes
			try {
				fujaba__Success = false;

				// check object match is really bound
				JavaSDM.ensure(match != null);
				fujaba__Success = true;
			} catch (JavaSDMException fujaba__InternalException) {
				fujaba__Success = false;
			}

			fujaba__Success = true;
		} catch (JavaSDMException fujaba__InternalException) {
			fujaba__Success = false;
		}

		// story pattern set success
		try {
			fujaba__Success = false;

			// check object ruleResult is really bound
			JavaSDM.ensure(ruleResult != null);
			// iterate to-many link matches from ruleResult to match
			fujaba__Success = false;

			fujaba__IterRuleResultToMatch = ruleResult.getMatches().iterator();

			while (!(fujaba__Success)
					&& fujaba__IterRuleResultToMatch.hasNext()) {
				try {
					match = (Match) fujaba__IterRuleResultToMatch.next();

					// check object match is really bound
					JavaSDM.ensure(match != null);

					fujaba__Success = true;
				} catch (JavaSDMException fujaba__InternalException) {
					fujaba__Success = false;
				}
			}
			JavaSDM.ensure(fujaba__Success);
			// assign attribute ruleResult
			ruleResult.setSuccess(true);
			fujaba__Success = true;
		} catch (JavaSDMException fujaba__InternalException) {
			fujaba__Success = false;
		}

		return ruleResult;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eInvoke(int operationID, EList<?> arguments)
			throws InvocationTargetException {
		switch (operationID) {
		case RulesPackage.BOARD_RULE___PERFORM_FWD_BOARD_0__BOARD:
			return perform_FWD_Board_0((Board) arguments.get(0));
		case RulesPackage.BOARD_RULE___IS_APPROPRIATE_FWD_BOARD_0__BOARD:
			return isAppropriate_FWD_Board_0((Board) arguments.get(0));
		case RulesPackage.BOARD_RULE___PERFORM_BWD_FILE_0__FILE:
			return perform_BWD_File_0((File) arguments.get(0));
		case RulesPackage.BOARD_RULE___IS_APPROPRIATE_BWD_FILE_0__FILE:
			return isAppropriate_BWD_File_0((File) arguments.get(0));
		case RulesPackage.BOARD_RULE___PERFORM_BWD_NODE_0__NODE:
			return perform_BWD_Node_0((Node) arguments.get(0));
		case RulesPackage.BOARD_RULE___IS_APPROPRIATE_BWD_NODE_0__NODE:
			return isAppropriate_BWD_Node_0((Node) arguments.get(0));
		}
		return super.eInvoke(operationID, arguments);
	}

} //BoardRuleImpl
